package org.jeecg.modules.ws.job;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import jodd.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.ws.service.IWsEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author ZJJ
 * @date 2025-03-03 10:07
 * @copyright Copyright (c) 2025 ZJJ
 */
@Slf4j
@Component
public class EmployeeJob {

    @Autowired
    private IWsEmployeeService employeeService;

    /**
     * 每天凌晨2点执行定时任务
     */
    @Scheduled(cron = "0 0 2 * * ?")
    public void authUpdateEmployee() {
        Date now = new Date();
        String param = System.getProperty("employee.job.date");
        try {
            if (StringUtil.isNotBlank(param)) {
                now = DateUtil.parse(param);
            }
        } catch (Exception e) {
            log.error("解析入参日期格式异常", e);
        }
        employeeService.updateByDate(now);
    }
}
